﻿using MediatR;
using SlaughterItem.Common.Domains.ListWeek2;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.BasicSettings
{
    public class ProductSuretenHandler : IRequestHandler<ProductSuretenCommend, Result>
    {
        private readonly IBaseRepositoryGet<Product> Product;

        public ProductSuretenHandler(IBaseRepositoryGet<Product> Product)
        {
            this.Product = Product;
        }

        public async Task<Result> Handle(ProductSuretenCommend request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var list = Product.GetAll().ToList();

                if (list != null)
                {
                    result.Code = (int)CommonErrorCode.Success;
                    result.Data = list;
                    result.Msg = "成功";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
